package me.wangshier.leetcode.medium;

/**
 * 2. 徒步旅行中的补给问题
 * @Author: tongqianwen
 * @Date: 2025/3/2
 */
public class Hiking {
    public static int solution(int n, int k, int[] data) {
        // 使用补买策略

        // 初始化最小花费
        int minCost = 0;

        // 遍历每一天
        for (int i = 0; i < n; i++) {
            // 计算当前天需要购买的食物数量
            int toBuy = minOfArrayInBeforeDays(i, k, data);

            // 更新最小花费
            minCost += toBuy;
        }

        return minCost;
    }

    public static int minOfArrayInBeforeDays(int currentIndex, int step, int[] data){
        int min = data[currentIndex];
        for(int i = 1; i < step; i++){
            if(currentIndex-i>=0){
                min = Math.min(min, data[currentIndex-i]);
            }
        }

        return min;
    }

    public static void main(String[] args) {
        // Add your test cases here

        System.out.println(solution(5, 2, new int[]{1, 2, 3, 3, 2}) == 9);
    }
}
